package interface_;

/**
 * @Package: interface_
 * @ClassName: InterfacePolimorphicArray
 * @Author: x2606
 * @CreateTime: 2022/3/12 10:40
 * @Description: 接口实现多态数组
 */

public class InterfacePolimorphicArray {
    public static void main(String[] args) {
        Usb[] usbs = new Usb[2];
        usbs[0]=new Camera_();
        usbs[1]=new Phone_();

        for (int i = 0; i < usbs.length; i++) {
            usbs[i].work();
            if (usbs[i] instanceof Phone_){
                //向下转型，调用子类特有属性
                ((Phone_) usbs[i]).call();
            }
        }

    }
}

interface Usb{
    public void work();
}
class Camera_ implements Usb{
    @Override
    public void work() {
        System.out.println("相机工作中");
    }
}
class Phone_ implements Usb{
    @Override
    public void work() {
        System.out.println("相机工作中");
    }
    public void call(){
        System.out.println("手机打电话");
    }
}
